using System;
using System.Data.Linq;

namespace RomanJendrusz.Amazon.ETL.Domain
{
    public class ListMania
    {
        private readonly EntitySet<ListItem> listItems;
        private EntityRef<Customer> owner;
        protected string ownerId;
        private char listType = 'M';
        private DateTime updated;

        protected virtual char ListType 
        {
            get { return listType; } 
            set {listType = value;}
        }

        public ListMania()
        {
            listItems = new EntitySet<ListItem>(onAdded, onRemoved);
            owner = new EntityRef<Customer>();
        }

        private void onAdded(ListItem obj)
        {
            if (obj != null)
            {
                obj.List = this;
            }
        }

        private void onRemoved(ListItem obj)
        {
            if (obj != null && obj.List == this)
            {
                obj.List = null;
            }
        }

        public string ListId { get; set; }
        public string ListUrl { get; set; }
        public string ListName { get; set; }
        public DateTime CreatedDate { get; set; }
        /// <summary>
        /// Gets or sets the row updated.
        /// </summary>
        /// <value>The row updated.</value>
        public DateTime Updated
        {
            get { return updated; }
        }

        /// <summary>
        /// Gets or sets the total items of all posible list items(not only books).
        /// </summary>
        /// <value>The total items.</value>
        public int TotalPossibleItems{ get; set;}
        
        /// <summary>
        /// Gets or sets the last updated. It also indicates if the items has been changed
        /// </summary>
        /// <value>The last updated.</value>
        public DateTime LastUpdated { get; set; }

        public EntitySet<ListItem> ListItems
        {
            get { return listItems; }
            set { listItems.Assign(value); }
        }

        public Customer Owner
        {
            get { return owner.Entity; }
            set { owner.Entity = value; }
        }
    }
}